<template>
  <div class="shangpinDialog">
    <el-dialog
      title="选择采购计划"
      :close-on-click-modal="false"
      :visible.sync="dialogTableVisible"
      width="75%">
      <el-row :gutter="20">
        <!--部门数据-->
        <el-col :span="3" :xs="24" style="max-height: 400px;overflow: auto">
          <div class="head-container">
            <el-tree
              :data="deptOptions"
              :props="defaultProps"
              :expand-on-click-node="false"
              :filter-node-method="filterNode"
              ref="tree"
              default-expand-all
              @node-click="handleNodeClick"
            />
          </div>
        </el-col>
        <el-col :span="21" :xs="24">
          <div class="pageTop">
            <el-form :model="queryParams" ref="queryParams" :inline="true" class="inputWidth"  style="padding: 0px 10px; padding-top: 20px;" >
              <el-form-item label="商品名称" >
                <el-input
                  v-model="queryParams.goodsName"
                  placeholder="请输入商品名称"
                  clearable
                  size="medium"
                />
              </el-form-item>
              <el-form-item label="商品编号" >
                <el-input
                  v-model="queryParams.goodsSn"
                  placeholder="请输入商品编号"
                  clearable
                  size="medium"
                />
              </el-form-item>
              <el-form-item label="仓库" prop="warehouseId">
                <el-select
                  v-model="queryParams.warehouseId"
                  placeholder="请选择"
                  clearable
                  size="medium">
                  <el-option
                    v-for="item in camgkuList"
                    :key="item.warehouseId"
                    :label="item.warehouseName"
                    :value="item.warehouseId">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="计划编码" >
                <el-input
                  v-model="queryParams.purchasePlan"
                  placeholder="请输入计划编码"
                  clearable
                  size="medium"
                />
              </el-form-item>
              <el-form-item label="" >
                <el-button type="primary" size="medium" @click="getList">搜 索</el-button>
              </el-form-item>

            </el-form>
          </div>
          <el-table
            highlight-current-row
            max-height="300"
            @row-click="rowClick"
            v-loading="loading"
            :data="dataList"
            stripe border style="margin-top: 20px"
            :header-cell-style="{background:'#eef1f6',color:'#606266'}">
            <el-table-column  width="35">
              <template slot-scope="scope">
                <el-radio :label="scope.row.purchasePlanId" v-model="radioId">&nbsp;</el-radio>
              </template>
            </el-table-column>
            <el-table-column align="center" label="序号" type="index" width="50"></el-table-column>
            <el-table-column align="center" label="计划编码"   property="purchasePlanNo"  width="180" ></el-table-column>
            <el-table-column align="center" label="仓库需求数"   property="purchasePlanAllqty"   ></el-table-column>
            <el-table-column align="center" label="采购计划名称"   property="purchasePlanName"   ></el-table-column>

<!--            <el-table-column align="center" label="预计采购数量（自己计算）"   property="ren"  width="200" ></el-table-column>-->
<!--            <el-table-column align="center" label="实际采购数量"   property="shouji"   ></el-table-column>-->
<!--            <el-table-column align="center" label="状态"   property="shouji"   ></el-table-column>-->
            <el-table-column align="center" label="运营人员"   property=" createUserName"   ></el-table-column>
            <el-table-column align="center" label="备注"   property="remark"  show-overflow-tooltip ></el-table-column>
          </el-table>
          <el-pagination
            style="margin-top: 20px;text-align: right"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :page-sizes="[10, 20, 30, 40]"
            :current-page="queryParams.current"
            :page-size="queryParams.size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
          </el-pagination>
        </el-col>
      </el-row>




      <div class="pageTop" style="padding:10px;margin-top: 15px;text-align: right">
        <el-button type="primary" size="medium" @click="determine" >确 定</el-button>
        <el-button  size="medium" @click="cancel" >关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import request from '@/utils/request'
export default {
  props: ['cgdData'],
  name: "Role",
  data() {
    return {
      camgkuList:[],
      total:0,
      radioId:'',
      ckname:'',
      loading:false,
      // 部门树选项
      deptOptions: undefined,
      defaultProps: {
        children: "child",
        label: "catName"
      },
      dataList:[],
      dialogTableVisible:true,
      queryParams:{
        current:1,
        size:10,
        catId:0,//分类id
        goodsName:'',
        goodsSn:'',
        purchasePlan:'',
        purchasePlanStatus:'3',
        isAutoUse:1,
        isEmploy:1,
        isManul:'',
      },
      multipleSelection:[],
    };
  },
  watch: {
    dialogTableVisible: function () {
      this.dialogTableVisible = true;//始终让他为true;
      this.cancel();//隐藏
    },
  },
  created() {
    console.log('接受',this.cgdData.isEmploy)
    this.queryParams.isEmploy = this.cgdData.isEmploy
    this.queryParams.isManul=this.cgdData.isManul
    //分类查询
    this.getcangku()
    this.getFenlei()

  },
  mounted() {

  },
  methods: {
    //获取仓库
    getcangku:function (){
      request({
        url: '/wh/warehouse/list',
        method: 'get',
      }).then(response => {
        this.camgkuList = response.data
      });
    },
    //分类查询
    getFenlei:function (){
      request({
        url: '/wh/products/categoryList',
        method: 'get',
        params:this.queryParams
      }).then(response => {
        this.deptOptions =response.data
        this.getList();
      });
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      console.log('节点单击',data.catId)
      this.queryParams.catId = data.catId
      this.getList();
    },
    rowClick(row){
      this.radioId=row.purchasePlanId;
      this.ckname=row.purchasePlanName
      console.log('单选',row)
    },
    //分页查询
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.queryParams.current = val
      this.getList()
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.queryParams.size = val
      this.getList()
    },
    //搜索
    getList:function (){
      this.loading=true
      request({
        url: '/wh/purchasePlan/findListByGoodsTypeAndGoodsName',
        method: 'get',
        params:this.queryParams
      }).then(response => {
        this.loading=false
        if(response.code=='200'){
          this.dataList = response.data.records
          this.total =response.data.total
        }else {
          this.dataList=[]
          this.$message({
            type: 'warning',
            message:response.msg
          });
        }
      });

    },
    //确定
    determine:function(){
      var obj={}
      obj.radioId =  this.radioId
      obj.ckname =  this.ckname
      obj.purchasePlanNo=this.purchasePlanNo

      this.$emit('callback',obj)//将submitModel的值传给父组件
    },
    //隐藏
    cancel:function(){
      // this.determine()
      this.$emit('callback','')//将submitModel的值传给父组件
    },

  }
};
</script>
<style scoped>
.shangpinDialog {

}



</style>
